package com.ruoyi.web.controller.mes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.domain.vo.MaterialInVo;
import com.ruoyi.web.domain.vo.MaterialInventoryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.mes.MesMaterialInventory;
import com.ruoyi.web.service.IMesMaterialInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料盘点Controller
 * 
 * @author levicash
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/mes/materialinventory")
public class MesMaterialInventoryController extends BaseController
{
    @Autowired
    private IMesMaterialInventoryService mesMaterialInventoryService;

    /**
     * 查询物料盘点列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesMaterialInventory mesMaterialInventory)
    {
        startPage();
        List<MesMaterialInventory> list = mesMaterialInventoryService.selectMesMaterialInventoryList(mesMaterialInventory);
        return getDataTable(list);
    }

    /**
     * 导出物料盘点列表
     */
    @Log(title = "物料盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesMaterialInventory mesMaterialInventory)
    {
        List<MesMaterialInventory> list = mesMaterialInventoryService.selectMesMaterialInventoryList(mesMaterialInventory);
        ExcelUtil<MesMaterialInventory> util = new ExcelUtil<MesMaterialInventory>(MesMaterialInventory.class);
        util.exportExcel(response, list, "物料盘点数据");
    }

    /**
     * 获取物料盘点详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesMaterialInventoryService.selectMesMaterialInventoryById(id));
    }

    /**
     * 新增物料盘点
     */
    @Log(title = "物料盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMaterialInventory mesMaterialInventory)
    {
        return toAjax(mesMaterialInventoryService.insertMesMaterialInventory(mesMaterialInventory));
    }

    /**
     * 修改物料盘点
     */
    @Log(title = "物料盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMaterialInventory mesMaterialInventory)
    {
        return toAjax(mesMaterialInventoryService.updateMesMaterialInventory(mesMaterialInventory));
    }

    /**
     * 删除物料盘点
     */
    @Log(title = "物料盘点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesMaterialInventoryService.deleteMesMaterialInventoryByIds(ids));
    }

    /**
     * 查询物料盘点明细列表
     */
    @GetMapping("/detail")
    public TableDataInfo detail(MaterialInventoryVo materialInventoryVo) {
        startPage();
        Map<String, Object> map = new HashMap<>();
        map.put("inventorytCode", materialInventoryVo.getInventorytCode());
        map.put("materialName", materialInventoryVo.getMaterialName());
        map.put("specs", materialInventoryVo.getSpecs());
        map.put("beginTime", materialInventoryVo.getBeginTime());
        map.put("endTime", materialInventoryVo.getEndTime());
        map.put("status", materialInventoryVo.getStatus());
        List<MaterialInventoryVo> list = mesMaterialInventoryService.selectMesMaterialInventoryDetailList(map);
        return getDataTable(list);
    }
}
